# 使用nvidia/cuda:11.7.1-cudnn8-runtime-ubuntu22.04作为基础镜像
# ok1
#FROM nvidia/cuda:11.7.1-cudnn8-runtime-ubuntu22.04
#FROM pytorch/pytorch:2.0.1-cuda11.7-cudnn8-runtime
#FROM nvcr.io/nvidia/pytorch:2.0.1-cuda11.7-cudnn8-runtime

#FROM walkerlab/pytorch:cuda-11.7.1-pytorch-1.13.0-torchvision-0.13.0-torchaudio-0.13.0-ubuntu-20.04
FROM nvidia/cuda:11.7.1-cudnn8-runtime-ubuntu22.04

#FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04
#切换国内源
RUN sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
RUN sed -i s@/security.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
#必须
RUN sed -i 's/ports.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list

RUN apt-get clean
RUN apt-get update

RUN apt-get install -y \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
# 安装Python编译依赖，下载并编译Python，并设置Python 3.10为默认Python版本
RUN apt-get update && apt-get install -y \
    wget \
    build-essential \
    libssl-dev \
    zlib1g-dev \
    libncurses5-dev \
    libncursesw5-dev \
    libreadline-dev \
    libsqlite3-dev \
    libgdbm-dev \
    libdb5.3-dev \
    libbz2-dev \
    libexpat1-dev \
    liblzma-dev \
    libffi-dev \
    libgdbm-compat-dev \
    curl \
    apt-utils\
    && wget https://registry.npmmirror.com/-/binary/python/3.10.12/Python-3.10.12.tar.xz -O /tmp/Python-3.10.12.tar.xz \
    && tar xvf /tmp/Python-3.10.12.tar.xz -C /tmp \
    && cd /tmp/Python-3.10.12 \
    && ./configure --enable-optimizations --with-ensurepip=install \
    && make -j $(nproc) \
    && make altinstall \
    && update-alternatives --install /usr/bin/python python /usr/local/bin/python3.10 1 \
    && update-alternatives --install /usr/bin/pip pip /usr/local/bin/pip3.10 1 \
    && rm -rf /tmp/Python-3.10.12.tar.xz /tmp/Python-3.10.12
#    && apt-get install -y git \
#    && curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash \
#    && apt-get install -y git-lfs \
#    && pip install --upgrade pip
RUN apt-get install -y git \
    && curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash \
    && apt-get install -y git-lfs
RUN pip install --upgrade pip  -i https://pypi.tuna.tsinghua.edu.cn/simple
#设置工作目录
WORKDIR /root/Llama2-Chinese
#
#RUN pip install torch torchvision torchaudio

# 从git上克隆llama2-chinese仓库
RUN git clone https://gitee.com/ai_deeplearn/Llama2-Chinese.git /root/Llama2-Chinese

# auto-gptq 依赖 transformers
RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
#RUN pip install setuptools torch torchvision torchaudio -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install setuptools -i https://pypi.tuna.tsinghua.edu.cn/simple

RUN pip install transformers==4.31.0  -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN BUILD_CUDA_EXT=0 pip install auto-gptq  -i https://pypi.tuna.tsinghua.edu.cn/simple
#RUN BUILD_CUDA_EXT=0 pip install --upgrade --no-cache-dir --use-deprecated=legacy-resolver  auto-gptq
# 使用pip安装requirements.txt
RUN pip install -r requirements.txt

#克隆Hugging Face仓库
#RUN  git clone https://huggingface.co/FlagAlpha/Llama2-Chinese-7b-Chat
#ADD ../meta-models/FlagAlpha/Llama2-Chinese-7b-Chat/ /root/Llama2-Chinese/Llama2-Chinese-7b-Chat/

#开启7860端口
EXPOSE 7860 

#设置启动命令
ENTRYPOINT ["python", "examples/chat_gradio.py", "--model_name_or_path", "/root/Llama2-Chinese/Llama2-Chinese-7b-Chat/"]
